<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Deal extends Base
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //获取搜索数据
        $data = input('get.');
        $sdata = [];
        if (!empty($data['category_id'])) {
            $sdata['category_id'] = $data['category_id'];
        }
        if (!empty($data['city_id'])) {
            $sdata['city_id'] = ['in', $data['city_id']];
        }
        if (!empty($data['start_time']) && !empty($data['end_time']) && strtotime($data['start_time']) < strtotime($data['end_time'])) {
            $sdata['create_time'] = [
                ['gt', $data['start_time']],
                ['lt', $data['end_time']]
            ];
        }
        if (!empty($data['name'])) {
            $sdata['name'] = ['like', '%' . $data['name'] . '%'];
        }
        $deals = model('deal')->getNormalDeals($sdata);
//        $deals->city_id = model('city')->get(['id'=>$deals['city_id']]);
        //获取分类数据
        $categorys = model('category')->getNormalFirstCategory();
        //获取城市数据
        $citys = model('city')->getNormalCitys();
        return $this->fetch('', ['categorys' => $categorys, 'citys' => $citys, 'deals' => $deals]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function apply()
    {
        //获取分类数据
        $categorys = model('category')->getNormalFirstCategory();
        //获取城市数据
        $citys = model('city')->getNormalCitys();
        //获取团购商品数据
        $deal = model('Deal')->getDealByStatus();
        return $this->fetch('', ['deal' => $deal, 'categorys' => $categorys, 'citys' => $citys]);
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request $request
     * @param  int $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
